<?php
/*
*
* cms.Archives  内容发布系统 自定义表单
*
* =========================================================
* 零起飞网络 - 专注于网站建设服务和行业系统开发
* 以质量求生存，以服务谋发展，以信誉创品牌 !
* ----------------------------------------------
* @copyright	Copyright (C) 2017-2018 07FLY Network Technology Co,LTD (www.07FLY.com) All rights reserved.
* @license    For licensing, see LICENSE.html or http://www.07fly.xyz/crm/license
* @author ：kfrs <goodkfrs@QQ.com> 574249366
* @version ：1.0
* @link ：http://www.07fly.xyz
*/

namespace app\workflow\controller;

use think\db;

/**
 * 自定义表单控制器
 */
class WorkflowDiyForm extends WorkflowBase
{


    /**
     * 析构函数
     */
    public function __construct()
    {
        // 执行父类构造方法
        parent::__construct();
    }

    /**
     * 我的申请=》列表
     */
    public function show_app()
    {
        if (IS_POST) {
            $where = [];
            if (!empty($this->param['keywords'])) {
                $where['name'] = ['like', '%' . $this->param['keywords'] . '%'];
            }
            $order_by = $this->logicWorkflowDiyForm->getOrderby($this->param);
            $list = $this->logicWorkflowDiyForm->getWorkflowDiyFormList($where, true, $order_by);
            foreach ($list as &$row){
                $where['diy_form_id']=$row['id'];
                $where['create_user_id']=SYS_USER_ID;
                $row['data_cnt']=$this->logicWorkflowDiyData->getWorkflowDiyDataCount($where);
            }
            return $list;
        }
        return $this->fetch('show_app');
    }

    /**
     * 列表
     */
    public function show()
    {
        if (IS_POST) {
            $where = [];
            if (!empty($this->param['keywords'])) {
                $where['name'] = ['like', '%' . $this->param['keywords'] . '%'];
            }
            $order_by = $this->logicWorkflowDiyForm->getOrderby($this->param);
            $list = $this->logicWorkflowDiyForm->getWorkflowDiyFormList($where, true, $order_by);
            return $list;
        }
        return $this->fetch('show');
    }

    /**
     * 添加
     */
    public function add()
    {
        IS_POST && $this->jump($this->logicWorkflowDiyForm->workflowDiyFormAdd($this->param));
        return $this->fetch('add');
    }

    /**
     * 编辑
     */
    public function edit()
    {

        IS_POST && $this->jump($this->logicWorkflowDiyForm->workflowDiyFormEdit($this->param));

        $info = $this->logicWorkflowDiyForm->getWorkflowDiyFormInfo(['id' => $this->param['id']]);

        $this->assign('info', $info);

        //可选择流程模板
        $where['business_type'] = $info['ext_table'];
        $list = $this->logicWorkflow->getWorkflowList($where, 'id,name', 'sort asc', false);
        $this->assign('workflow_list', $list);

        return $this->fetch('edit');
    }

    /**
     * 数据状态设置
     */
    public function del()
    {
        $where = empty($this->param['id']) ? ['id' => 0] : ['id' => $this->param['id']];
        $this->jump($this->logicWorkflowDiyForm->workflowDiyFormDel($where));
    }
}
